const router = require('koa-router')()
var mongoose = require('mongoose');
var act = require('../controller/common.js');
var Files = mongoose.model('File');
router.prefix('/f');

//获取单个的项目信息
router.get('/:id', async (ctx, next) =>{
    let _id = ctx.params.id;
  let data = await act.getFileById(_id);
  ctx.body = data;
})
//创建文件夹 ok
router.post('/:id', async (ctx, next) =>{
  let _id = ctx.params.id;
  let req = ctx.request;
  let name = req.body.name;
  let file = new Files({
    name :name,
    apiListId : _id,
  })
  let data = await act.createFileByName(file);
  ctx.body = data;
})
//查找项目的所有文件夹 ok
router.get('/f/:id', async (ctx, next) =>{
  let _id = ctx.params.id;
  let data = await act.getFileByProjectId(_id);
  ctx.body = data;
})

module.exports = router